package pl.streamsoft.currencyApp.services.test;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import pl.streamsoft.currencyApp.model.Currency;
import pl.streamsoft.currencyApp.services.DataBaseCurrencyService;
import pl.streamsoft.currencyApp.services.ICurrencyService;
import pl.streamsoft.currencyApp.services.WebCurrencyService;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
    	Date date = Calendar.getInstance().getTime();
    	
    	BigDecimal minCurrencyValue = new BigDecimal(3.0);
    	BigDecimal maxCurrencyValue = new BigDecimal(4.0);
    	
    	BigDecimal imposibleCurrencyValue = new BigDecimal(4000.0);
    	
        ICurrencyService webService = new WebCurrencyService();
        Collection<Currency> currencies = webService.getCurrencies(date);
        
        ICurrencyService dbService = new DataBaseCurrencyService();
        dbService.addCurrency(currencies);
        
        currencies =  dbService.getCurrencies(date);    
        System.out.println(currencies.size());
        
        currencies =  dbService.getCurrencies(date, date);    
        System.out.println(currencies.size());
        
        dbService.remove(currencies.iterator().next());
        
        currencies =  dbService.getCurrencies(date, date);    
        System.out.println(currencies.size());
        
        Currency currency =  dbService.getCurrencyByCode(date, "EUR");    
        System.out.println(currency == null ? "null" : currency.getCurrencyCode());
        
        currency =  dbService.getCurrencyByName(date, "euro");    
        System.out.println(currency == null ? "null" : currency.getCurrencyCode());
        
        currencies =  dbService.getCurrenciesByValue(date, minCurrencyValue);
        System.out.println(currencies == null ? "null" : currencies.size());
        
        currencies =  dbService.getCurrenciesByValue(date, minCurrencyValue, maxCurrencyValue);
        System.out.println(currencies == null ? "null" : currencies.size());
        
        currencies =  dbService.getCurrenciesByValue(date, imposibleCurrencyValue);
        System.out.println(currencies == null ? "null" : currencies.size());
        
        currencies =  dbService.getLatestCurrencies();
        System.out.println("Last: " + (currencies == null ? "null" : currencies.size()));
    }
}

